package cn.rslee.uaas.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 描述：
 *
 * <pre>HISTORY
 * ****************************************************************************
 *  ID   DATE               PERSON                 REASON
 *  1    2016年3月2日         rslee               Create
 * ****************************************************************************
 * </pre>
 * @author rslee
 * @since 1.0
 */
public class U {
	
	final static Logger logger = LoggerFactory.getLogger(U.class);
	
	//yyyy-mm-dd转换为Date对象
	static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
	
	public static Date getDayBefore(int days){
		Date d = toDate(sf.format(new Date()));
		return addDay(d,-days);
	}
	
	public static Date toDate(String days){
		try {
			return sf.parse(days);
		} catch (ParseException e) {
			logger.warn("exchange date fail,the values is:"+days, e);
			return null;
		}
	}
	 
	public static Date addDay(Date day,int days){
		Calendar c = Calendar.getInstance();
		c.setTime(day);
		c.add(Calendar.DAY_OF_YEAR, days);
		
		return c.getTime();
	}

}
